﻿using System.Collections.Generic;
using System.Reflection;

namespace sinetd.Services
{
    public class ServiceWrapper
    {
        private object service;
        private Dictionary<string, MethodInfo> castMethod;

        //protected - only for now
        public sinetd.Protocols.IProtocol Protocol;

        protected object InvokeCall(string methodName, object[] objs)
        {
            if (!castMethod.ContainsKey(methodName))
                castMethod[methodName] = service.GetType().GetMethod(methodName);

            return castMethod[methodName].Invoke(service, objs);
        }

        public ServiceWrapper(string serviceName, string protName)
        {
            castMethod = new Dictionary<string, MethodInfo>();

            Protocol = sinetd.Protocols.Manager.Create(protName);
            service = (object)sinetd.Services.Manager.Create(serviceName);
        }
    }
}
